package edu.kaist.cs408.pof.backend.provider;

import org.bson.types.ObjectId;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: duyleekun
 * Date: 5/14/12
 * Time: 7:13 PM
 * To change this template use File | Settings | File Templates.
 */
public class ObjectIdSerializer extends JsonSerializer<ObjectId> {
	/**
	 * Method that can be called to ask implementation to serialize
	 * values of type this serializer handles.
	 *
	 * @param value    Value to serialize; can <b>not</b> be null.
	 * @param jgen     Generator used to output resulting Json content
	 * @param provider Provider that can be used to get serializers for
	 *                 serializing Objects value contains, if any.
	 */
	@Override
	public void serialize(ObjectId value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
		jgen.writeString(value.toStringMongod());
	}
}
